import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-03-14
 * Time:18:12
 */
public class main3 {
    public static void sqort1(int[] array) {
        for(int i=0;i< array.length-1;i++)
        {
            for(int c=0;c< array.length-i-1;c++)
            {
                if(array[c]>array[c+1])
                {
                    array[c]=array[c]^array[c+1];
                    array[c+1]=array[c]^array[c+1];
                    array[c]=array[c]^array[c+1];
                }
            }
        }

    }
    public static int sqort(int[] array,int sum) {
       int num=0;
       int right= array.length-1;
       int left=0;
      while(true)
      {
           num=(right+left)/2;
           if(array[num]==sum)
           {
               break;
           }
           else if(array[num]<sum)
           {
               left=num;
           }
           else
           {
                right=num;
           }
      }
        return num+1;
    }
    public static void main(String[] args) {
        int[] array=new int[]{1,3,2,4,5,6,7,8,9};
        Scanner sc=new Scanner(System.in);
        System.out.println("查找值：");
       int sum=sc.nextInt();
        sqort1(array);
        System.out.println(Arrays.toString(array));
        System.out.println(sqort(array,sum));
    }
}
